layui.define(['form', 'laydate', 'table', 'checkApi'], function (exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var checkApi = layui.checkApi;
    var userTable = null;

    var view = {
        init: function () {
            this.initSearchForm();
            Lib.initGenrealForm($("#searchForm"), form);
            this.initSubmit();
        },
        initSearchForm: function () {
            $.ajax({
                url: "/admin/GetManageCom/getManageCom.json",
                type: "POST",
                dataType: "json",
                success: function (result) {
                    var list = result;    //返回的数据
                    var server = document.getElementById("manageCom"); //server为select定义的id
                    for (var p in list) {
                        var option = document.createElement("option");  // 创建添加option属性
                        option.setAttribute("value", p); // 给option的value添加值
                        option.innerText = list[p];     // 打印option对应的纯文本
                        server.appendChild(option);           //给select添加option子标签
                        form.render("select");            // 刷性select，显示出数据
                    }
                }
            });
        },


        initSubmit: function () {
            $("#search").click(function () {
                var formPara = $('#searchForm').serializeJson();
                $.ajax({
                    url: "/admin/GetManageCom/isRe.json",
                    type: "POST",
                    data : formPara,
                    dataType: "text",
                    success: function (result) {
                        if (result == "1") {
                            Common.openConfirm("该范围数据已抽取,确定要再次抽取吗", function () {
                                Common.alert("数据抽取中,请等待抽取结果");
                                checkApi.check($('#searchForm'), function () {
                                    alert("抽取成功");
                                });
                            });
                        }else {
                            Common.alert("数据抽取中,请等待抽取结果");
                            checkApi.check($('#searchForm'), function () {
                                alert("抽取成功");
                            });
                        }
                    }
                });

            });
        }

    };


    exports('index', view);

});